: A Member of Elysium <st103@sco.zsi.pwr.wroc.pl> wrote:
: >Hi!
: >
: >I'm going to write some math stuff for my c64 byt i have a little problem:
: >i need a 16 bits * 16 bits multiplication program and 16 bits / 8 bits or 8 bits / 8 bits division program that will return not the integer and fractional part of the number. I dont expect ANY optimized solutions i just wan a basic version that is slow but works. Can any one help me? Aspecialy with the division ?
: >
: >Kris
: >
: Straightforward 16-bit routines, coming right up:
: *------------------------
: * 16-bit Multiply routine
: * ACC*AUX -> [ACC,EXT] (low,hi) 32-bit result
: MULT LDA #0
: STA EXT+1
: LDY #$11
: ]LOOP LSR EXT+1
: ROR
: ROR ACC+1
: ROR ACC
: BCC MUL2
: CLC
: ADC AUX
: PHA
: LDA AUX+1
: ADC EXT+1
: STA EXT+1
: PLA
: MUL2 DEY
: BNE ]LOOP
: STA EXT
: RTS
: * Divide routine
: * ACC/AUX -> ACC, remainder in EXT
: DIV LDA #0
: STA EXT+1
: LDY #$10
: ]LOOP ASL ACC
: ROL ACC+1
: ROL
: ROL EXT+1
: PHA
: CMP AUX
: LDA EXT+1
: SBC AUX+1
: BCC DIV2
: STA EXT+1
: PLA
: SBC AUX
: PHA
: INC ACC
: DIV2 PLA
: DEY
: BNE ]LOOP
: STA EXT
: RTS
: Note that I did not write these; I lifted them off the Merlin assembler disk.
: They work just like you would write one: you have two numbers, A and B.
: Multiply A by each power of two contained in B. They are the most efficient
: implementation of this that I have seen though (if you want to make it just
: a little faster, change PLA/PHA to TXA/TAX, or store ACC in X, etc.).
: evetS
Ok. i'm very satisfied with muls routine but ineed abit different divisin routine. it returns me the integer part of the results and the REST if i understood good.. but i need it to return me the rest in such a format:
f.e.
5 div 2 = 2 and 128
---
256
7 div 3 = 2 and 85
---
256
have you got the point?? But thanx for thesr routines !!! i will certainly use them.
Kris.
p.s. ANY other postings on this subject are VERY welcome